package 中等;

import javax.xml.soap.Node;

public class 填充每个节点的下一个右侧节点指针116 {

    public static void main(String[] args) {

    }

    public TreeNode connect(TreeNode root) {
        if (root==null){
            return null;
        }
        root.next = null;
        connectTwoNode(root.left,root.right);
        return root;
    }

    public void connectTwoNode(TreeNode node1,TreeNode node2) {
        if (node1 == null || node2 == null){
            return ;
        }

        node1.next = node2;

        connectTwoNode(node1.left,node1.right );
        connectTwoNode(node2.left,node2.right );
        connectTwoNode(node1.right, node2.left);
    }
}
